package com.example.projectmanagement.repository.study;

import com.example.projectmanagement.model.User;
import com.example.projectmanagement.model.study.Course;
import com.example.projectmanagement.model.study.CourseEnrollment;
import com.example.projectmanagement.model.study.EnrollmentStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface CourseEnrollmentRepository extends JpaRepository<CourseEnrollment, Long> {
    
    @Query("SELECT e FROM CourseEnrollment e WHERE e.user = :user AND e.course = :course")
    Optional<CourseEnrollment> findByUserAndCourse(@Param("user") User user, @Param("course") Course course);
    
    @Query("SELECT e FROM CourseEnrollment e WHERE e.course = :course AND e.status = :status")
    List<CourseEnrollment> findByCourseAndStatus(@Param("course") Course course, @Param("status") EnrollmentStatus status);
    
    @Query("SELECT e FROM CourseEnrollment e WHERE e.course = :course")
    List<CourseEnrollment> findByCourse(@Param("course") Course course);
    
    @Query("SELECT e FROM CourseEnrollment e WHERE e.user = :user AND e.status = :status")
    List<CourseEnrollment> findByUserAndStatus(@Param("user") User user, @Param("status") EnrollmentStatus status);
    
    @Query("SELECT e FROM CourseEnrollment e WHERE e.user = :user")
    List<CourseEnrollment> findByUser(@Param("user") User user);
}